import web
from datetime import datetime

urls = (
    "/home/(.*)", "home",
    "/upper/(.*)", "upper",
    "/lower/(.*)", "lower"
)


print(f"load {datetime.now()}")
from langchain_config import qa_chain

print(f"start {datetime.now()}")
app = web.application(urls, globals())


class home:
    def GET(self, text):
        try:
            result = qa_chain({"query": text})
            return f"q: {text}\na: {result['result']}"
            # return f'>{text}'
        except Exception as e:
            return f'error {str(e)}'


class upper:
    def GET(self, text):
        print("input:" + text)
        return text.upper()


class lower:
    def GET(self, text):
        print("input:" + text)
        return text.lower()


if __name__ == "__main__":
    app.run()
